package com.miao.im.support.page;

import lombok.Data;

/**
 * @Auther: miaoguoxin
 * @Date: 2019/10/19 14:54
 * @Description: 分页辅助工具
 */
@Data
public class Page<T> {
    /**当前第几页*/
    private int pageNumber;
    /**每页多少条数据*/
    private int pageSize;
    /**数据查询总条数*/
    private int totalCount;
    /**是否需要统计查询条件,默认开启*/
    private transient boolean count = true;
    /**返回的数据*/
    private T data;

    public Page(int pageNumber, int pageSize) {
        this.setPageNumber(pageNumber);
        this.setPageSize(pageSize);
    }

    public Page(int pageNumber, int pageSize, boolean count) {
        this(pageNumber, pageSize);
        this.count = count;
    }

    public Page(int pageNumber, int pageSize, int totalCount, T data) {
        this(pageNumber, pageSize, false);
        this.totalCount = totalCount;
        this.data = data;
    }

    public void setPageNumber(int pageNumber) {
        if (pageNumber <= 0) {
            this.pageNumber = 1;
        } else {
            this.pageNumber = pageNumber;
        }
    }


    public void setPageSize(int pageSize) {
        if (pageSize <= 0) {
            this.pageSize = 1;
        } else {
            this.pageSize = pageSize;
        }
    }
}
